/* =============================================================
 * Your Grandmother's guide to Algorithms
 * =============================================================
 *
 * Copyright (c) 2007, Saverio Miroddi
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 * 
 *     * Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright 
 *       notice, this list of conditions and the following disclaimer in the 
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the SaverioMiroddiSoftware nor the names of its 
 *       contributors may be used to endorse or promote products derived from 
 *       this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 * ---------------------------
 * ShowBTree.java
 * ---------------------------
 *
 */
package utils.treegui;

import java.io.IOException;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

import treegui.TreePanel;
import treegui.nodewrappers.GuiBTreeNode;
import btree.AbstractNode;
import btree.BTree;

@SuppressWarnings({"unused"})
public class ShowBTree 
{
	private static final Random rnd = new Random();
	
	public static void main(String... args) throws IOException {
		new ShowBTree();
	}
	
	public ShowBTree() 
			throws IOException
	{
		final int TOT_ELEMS = 32;
		final int ORDER = 2;
		
		Set<Integer> randNums = getValues(TOT_ELEMS);
		AbstractNode treeRoot = getTestTree(randNums, ORDER);
		
		GuiBTreeNode guiTree = new GuiBTreeNode(treeRoot);
		TreePanel.showInFrame(guiTree);
	}
	
	private Set<Integer> getValues(int totElems) {
		Set<Integer> values = new HashSet<Integer>();
		
		for (int i = 0; i < 7; i++)
			values.add(i);
		
//		for (int i = 0; i < totElems; i++)
//			randomNums.add(rnd.nextInt(100));
		
		return values;
	}

	private static AbstractNode getTestTree(Set<Integer> testNums, int order)
			throws IOException 
	{
		BTree tree = new BTree(order);
		
		for (int num : testNums) {
			tree.add(num, 10 * num);
			System.out.print(num + ", ");
		}
		System.out.println();
		
		return tree.getRootNode();
	}
}
